package com.cloud.gateway.config;

import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import reactor.core.publisher.Mono;

/**
 * redis限流规则配置类   只能开启一个
 */
//@Configuration
public class KeyResolverConfiguration
{
//    URI限流规则配置类
    @Bean
    public KeyResolver pathKeyResolver()
    {
        return exchange -> Mono.just(exchange.getRequest().getURI().getPath());
    }
//    IP限流：key-resolver: "#{@ipKeyResolver}"
//    @Bean
//    public KeyResolver ipKeyResolver()
//    {
//        return exchange -> Mono.just(exchange.getRequest().getRemoteAddress().getHostName());
//    }
//参数限流：key-resolver: "#{@parameterKeyResolver}"
//    @Bean
//    public KeyResolver parameterKeyResolver()
//    {
//        return exchange -> Mono.just(exchange.getRequest().getQueryParams().getFirst("userId"));
//    }
}
